package com.adee.netty.nio;

import java.nio.IntBuffer;

public class BasicBuffer {
    public static void main(String[] args) {
        IntBuffer buffer = IntBuffer.allocate(10);
        // 写缓冲
        for (int i = 0; i < buffer.capacity(); i++) {
            buffer.put(i * 2 + 1);
        }
        // 读缓冲
        buffer.flip();
        System.out.println("读缓冲：");
        while (buffer.hasRemaining()) {
            System.out.println(buffer.get());
        }
        // 再重新读一遍
        buffer.rewind(); // 指针重新跳到起始位置
        System.out.println("重新读缓冲：");
        while (buffer.hasRemaining()) {
            System.out.println(buffer.get());
        }
    }
}
